package wk.asm.test;

import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;

/**
 * Created by wangkuan at 2018-09-05 16:39
 */
public class MySubMethodVisitor extends MethodVisitor {
    private String superClassName;

    public MySubMethodVisitor(int version, MethodVisitor mv, String superClassName) {
        super(version, mv);

        this.superClassName = superClassName;
    }

    @Override
    public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean b) {
        //调用父类的构造函数时,改写父类名
        if (opcode == Opcodes.INVOKESPECIAL && "<init>".equals(name)) {
            owner = superClassName;
        }

        super.visitMethodInsn(opcode, owner, name, desc, b);
    }
}
